// import mongoServer from './src/mongo.js'
// import mysqlServer from './src/mysql.js'
const mongoServer = require('./src/mongo.js').mongoServer
const mysqlServer = require('./src/mysql.js').mysqlServer
class Fission {
    constructor(props) {
        // super(props);
            console.log("=========================================",props.ctx.mfutil)
        this.option = {
            // state: props.state || true,  //Boolean: true 真分享， false: 加分享
        
            ctx: props.ctx || {
                'platform': 'taobao',
                'env': 'node',
                'mixNick': 'z01IE98JVR+EUTRXq0dG0i0pTix+Oonf5VD0dnSUq8vAJo=',
                'data': {

                },
                'cloud': {},
                'mfutil': { "dbpattern": "mongo", "db": { "mongo": { "find": () => { } } } }
            }
        }
    }

    init(option) {
        // this.option.state = option.state || true;
        this.option.ctx = option.ctx
    }

    /**
       * @description: 添加数据
       * @param {string} user_id 用户 必传
       * @param {string} share_user_id 分享人 必传
       * @param {string} avatar  头像 必传
       */
    async addLog(data) {
        const { ctx } = this.option
        const { mfutil: { db, dbpattern } } = ctx
        const { user_id, avatar, share_user_id } = data
        console.log("11111111111111111111111111111",data)
        if (!user_id || !avatar || !share_user_id){ return { msg: "参数错误" }};
        try {
            let result;
            if (dbpattern == "mongo") {
                result = await mongoServer.addLog(db, data)
            } else {
                result = await mysqlServer.addLog(db, data)
            }
            return result
        } catch (err) {
            return err
        }
    }

    /**
  * @description: 添加数据
  * @param {string} user_id 用户 必传
  * @param {string} share_user_id 分享人 
  * @param {date} start_time  开始时间
  * @return {date} end_time   结束时间
  */
    async getLog(data) {
        const { ctx } = this.option
       
        const { mfutil: { db, dbpattern } } = ctx
        console.log(data,"===========dbdbdb============",db)
        const { user_id } = data
        console.log(user_id,"=======================",!user_id)
        if (!user_id){ return { msg: "参数错误" }};
        try {
            let result;
            if (dbpattern == "mongo") {
                result = await mongoServer.getLog(db, data)
            } else {
                result = await mysqlServer.getLog(db, data)
            }
            console.log("==========result==============",result)
            return result
        } catch (err) {
            return err
        }
    }

    /**
 * @description: 添加数据
 * @param {object} user_id 用户 必填
 * @param {object} share_user_id 分享人 
 * @param {date} start_time  开始时间
 * @return {date} end_time   结束时间
 */
    async getLogCount(data) {
        const { ctx } = this.option
        const { mfutil: { db, dbpattern } } = ctx
        const { user_id } = data
        if (!user_id){ return { msg: "参数错误" }};
        try {
            let result;
            if (dbpattern == "mongo") {
                result = await mongoServer.getLogCount(db, data)
            } else {
                result = await mysqlServer.getLogCount(db, data)
            }
            return result
        } catch (err) {
            return err
        }
    }
}

// export default Fission;
module.exports={
    Fission
}